import { RegisterFormType } from "~/type/user";

export const username = [{ required: true, message: "请输入用户名", trigger: "blur" }];
export const emailCode = [{ required: true, message: "请输入邮箱验证码", trigger: "blur" }];
export const password = { required: true, message: "请输入密码", trigger: "blur" };
export const captcha = [{ required: true, message: "请输入验证码", trigger: "blur" }];
export const email = [{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }]


export function validatePass(formValue: RegisterFormType, refs: any, refName: string): Function {
      return (rule: any, value: String, callback: Function) => {
            if (value === '') {
                  callback(new Error('请输入密码'));
            } else {
                  if (formValue.checkPassword !== '') {
                        refs[refName] && refs[refName].validateField('checkPass');
                  }
                  callback();
            }
      }
};


export function validateCheckPass(formValue: RegisterFormType): Function {
      return (rule: any, value: String, callback: Function) => {
            if (value === '') {
                  callback(new Error('请再次输入密码'));
            } else if (value !== formValue.password) {
                  callback(new Error('两次输入密码不一致!'));
            } else {
                  callback();
            }
      };
}

